;; Tests for the Unidata implementation

;; by Konrad Hinsen
;; last updated February 8, 2010

;; Copyright (c) Konrad Hinsen, 2009-2010. All rights reserved.  The use
;; and distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this
;; distribution.  By using this software in any fashion, you are
;; agreeing to be bound by the terms of this license.  You must not
;; remove this notice, or any other, from this software.

(ns multiarray.tests.unidata
  (:use [multiarray.protocol]
	[clojure.test :only (deftest is are run-tests)])
  (:require [multiarray.unidata :as implementation]))

(deftest shape-test-zeros
  (doseq [s [ [] [2] [3 2] [4 1 2] ]]
    (is (= (shape (implementation/zeros s)) s))))

(deftest rank-test-zeros
  (are [x y] (= x y)
       (rank (implementation/zeros []))    0
       (rank (implementation/zeros [2]))   1
       (rank (implementation/zeros [3 2])) 2))

(deftest type-test
  (doseq [el-class [Boolean/TYPE Byte/TYPE Short/TYPE Integer/TYPE
		    Float/TYPE Double/TYPE Object]]
    (is (= (element-class (implementation/zeros [3] el-class)) el-class))))

(deftest sample-test
  (are [x y] (= x y)
; can't do this test as is because Unidata arrays don't implement comparison
;    (sample (implementation/ma-range 10) 0 1 7 2) (implementation/ma-range 1 7 2)
       (shape (sample (implementation/zeros [3 3 2]) 2 1 2 1)) [3 3 1]
       (shape (sample (implementation/zeros [3 3 2]) 1 1 2 1)) [3 1 2]
       (shape (sample (implementation/zeros [3 3 2]) 0 1 2 1)) [1 3 2]))

(run-tests)
